#include "uefi.h"

void func1()
{
    puts("func1");
}

void func2()
{
    puts("func2");
}

void func3()
{
    puts("func3");
}

int efi_main() {
    gST->ConOut->OutputString(gST->ConOut, L"Hello, World!\r\n");
    puts("Hello, World!");
    // test for wcstoc8s and c8stowcs
    char str1[] = "Hello, World!\r\n";
    wchar_t *str2 = (wchar_t *) calloc(sizeof(wchar_t), strlen(str1));
    c8stowcs(str1, str2);
    gST->ConOut->OutputString(gST->ConOut, str2);
    wcstoc8s(str2, str1); // should be identical
    puts(str1);
    char c = getchar();
    char str3[] = {c, 0};
    puts(str3);
    printf("%d + %d = %d\n", 1, 1, 1 + 1);
    // test for FILE series
    FILE *file1 = fopen("\\1.txt", "a");
    puts("after fopen");
    fwrite("Test fwrite", sizeof(char), strlen("Test fwrite"), file1);
    fclose(file1);
    file1 = fopen("\\1.txt", "r");
    char *buf = (char *) calloc(sizeof(char), 114);
    fread(buf, sizeof(char), 16, file1);
    fclose(file1);
    puts(buf);
    free(buf);
    long int pointer = 0;
    FILE *fp = fopen("\\genshin.txt", "r");
    fseek(fp, 0, SEEK_END);
    pointer = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    char *buf2 = (char *) calloc(sizeof(char), (int) pointer + 5);
    fread(buf2, sizeof(char), pointer, fp);
    puts(buf2);
    fclose(fp);
    free(buf2);
    fp = fopen("\\genshin.txt", "r");
    do {
        c = fgetc(fp);
        printf("%c", c);
        if (feof(fp)) break;
    } while (true);

    puts("");

    atexit(func1);
    atexit(func2);
    atexit(func3);

    exit(EFI_SUCCESS);
    return EFI_SUCCESS;
}